package com.hnkywl.sts.entity.xsgl;

import com.hnkywl.sts.entity.BaseEntity;
import com.hnkywl.sts.entity.base.Sjzdz;
import com.hnkywl.sts.entity.cggl.Jsd;
import com.hnkywl.sts.entity.sys.Gg;
import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
import java.util.List;

/**
 * 说明：销售明细
 * 包:        com.hnkywl.sts.entity.xsgl
 * 类描述:    销售明细
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Entity
@Table(name = "T_BIZ_XSMX")
@Where(clause = "deleted!='1'")
public class Xsmx extends BaseEntity {
    @Id
    @SequenceGenerator(name = "seqXsmx", allocationSize = 1, sequenceName = "SEQ_BIZ_XSMX")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqXsmx")
    private Long id;

    /**
     * 卡号
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "KH_ID")
    private Kh kh;

    /**
     * 具体物资
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "JTWZ_ID")
    private Gg jtwz;

    // 长/宽
    private String ck;

    /**
     * 资金分配金额
     */
    @Formula("(select sum(t.zjfpje) from T_BIZ_JFMX t  where t.XSDMX_ID = ID)")
    private Double zjfpje;

    /**
     * 记重方式
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "JZFS_SJZDZ_ID")
    private Sjzdz jzfs;

    /**
     * 件数
     */
    private Integer js;

    /**
     * 销售成本
     */
    private Double xscb;

    /**
     * 数量
     */
    private Double sbsl = 0d;

    /**
     * 出库_件数
     */
    private Integer ck_js;

    /**
     * 出库_数量
     */
    private Double ck_sbsl = 0d;

    /**
     * 含税价
     */
    private Double hsj = 0d;

    /**
     * 不含税价
     */
    private Double bhsj = 0d;

    /**
     * 开票不含税价
     */
    private Double kpbhsj = 0d;

    /**
     * 库存报价
     */
    private Double kcbj = 0d;

    // 结算不含税金额
    private Double jsbhse = 0d;

    // 结算时，销售金额
    private Double jsse = 0d;

    /**
     * 成本单价，该成本单用于考核经营利润
     */
    private Double cbdj;
    /**
     * 成本金额
     * 2013.10.27添加结算单冲销功能后，成本金额字段移至Xsjsdmx实体
     */
    @Deprecated
    private Double cbje;

    /**
     * 出库不含税额
     */
    private Double ckbhse;

    /**
     * 备注
     */
    private String bz;

    @ManyToOne
    @JoinColumn(name = "XSD_ID")
    private Xsd xsd;

    //结算单
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "XSJSD_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Jsd xsjsd;

    /**
     * 销售明细
     */
    @OneToMany(fetch = FetchType.LAZY, targetEntity = Jfmx.class)
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @JoinColumn(name = "XSDMX_ID")
    private List<Jfmx> jfmxList;

    /**
     * 已结算
     */
    private Boolean yjs = false;

    /**
     * 明细行序号
     */
    private Long mxh;

    /**
     * 价格的计算方式
     */
    private String jsfs;

    @Formula("( select ROUND(mx.xscb*mx.ck_sbsl,2) from t_biz_xsmx mx left join t_biz_xsd x on mx.xsd_id = x.id where mx.id = ID and mx.DELETED!=1)")
    private Double xscbzh;

    @Formula("(select (ROUND(ROUND(mx.HSJ * mx.CK_SBSL, 2) / (1 + x.SL / 100), 2) - ROUND(mx.xscb*mx.ck_sbsl,2)) from t_biz_xsmx mx left join t_biz_xsd x on mx.xsd_id = x.id where mx.id = ID and mx.DELETED!=1)")
    private Double xslr;

    /**
     * 购货金额
     */
    @Formula("(select Round(sum(nvl(t.SJDJ,0)*t.sbsl),2) from T_BIZ_XSMX t left join t_biz_xsd x on t.xsd_id = x.id where t.id = ID and t.DELETED!=1)")
    private Double ghje;

    /**
     * 税额
     */
    private Double se;

    private String hang_resource_number;

    /**
     * 优惠价格，支付的保证金利息
     */
    private Double yhjg;

    /**
     * 实际单价
     */
    private Double sjdj = 0d;

    //实际购货金额
    private Double sjghje;

    //贴现息
    private Double txx;

    //代理费
    private Double dlf;

    //资金占用费
    private Double zjzyf;

    //现款优惠
    private Double xkyh;


    //销售系统销售单号
    private String xsxt_xsdh;

    //销售系统销售价格
    private Double xsxt_price;

    //销售系统发货日期
    private Date xsxt_fhrq;

    //销售系统号
    private String xsxt_htbm;
    //车号
    private String carNo;
    //捆包号
    private String bindNo;

    private Double xsmxYe;

    public Double getZjfpje() {
        return zjfpje;
    }

    public void setZjfpje(Double zjfpje) {
        this.zjfpje = zjfpje;
    }

    public Double getXsmxYe() {
        return xsmxYe;
    }

    public void setXsmxYe(Double xsmxYe) {
        this.xsmxYe = xsmxYe;
    }

    public String getXsxt_htbm() {
        return xsxt_htbm;
    }

    public void setXsxt_htbm(String xsxt_htbm) {
        this.xsxt_htbm = xsxt_htbm;
    }

    public String getCarNo() {
        return carNo;
    }

    public void setCarNo(String carNo) {
        this.carNo = carNo;
    }

    public String getBindNo() {
        return bindNo;
    }

    public void setBindNo(String bindNo) {
        this.bindNo = bindNo;
    }

    public String getXsxt_xsdh() {
        return xsxt_xsdh;
    }

    public void setXsxt_xsdh(String xsxt_xsdh) {
        this.xsxt_xsdh = xsxt_xsdh;
    }

    public Double getXsxt_price() {
        return xsxt_price;
    }

    public void setXsxt_price(Double xsxt_price) {
        this.xsxt_price = xsxt_price;
    }

    public Date getXsxt_fhrq() {
        return xsxt_fhrq;
    }

    public void setXsxt_fhrq(Date xsxt_fhrq) {
        this.xsxt_fhrq = xsxt_fhrq;
    }

    public Double getKpbhsj() {
        return kpbhsj;
    }

    public void setKpbhsj(Double kpbhsj) {
        this.kpbhsj = kpbhsj;
    }

    public Double getSjghje() {
        return sjghje;
    }

    public void setSjghje(Double sjghje) {
        this.sjghje = sjghje;
    }

    public Double getTxx() {
        return txx;
    }

    public void setTxx(Double txx) {
        this.txx = txx;
    }

    public Double getDlf() {
        return dlf;
    }

    public void setDlf(Double dlf) {
        this.dlf = dlf;
    }

    public Double getZjzyf() {
        return zjzyf;
    }

    public void setZjzyf(Double zjzyf) {
        this.zjzyf = zjzyf;
    }

    public Double getXkyh() {
        return xkyh;
    }

    public void setXkyh(Double xkyh) {
        this.xkyh = xkyh;
    }


    public Double getSjdj() {
        return sjdj;
    }

    public void setSjdj(Double sjdj) {
        this.sjdj = sjdj;
    }

    public Double getYhjg() {
        return yhjg;
    }

    public void setYhjg(Double yhjg) {
        this.yhjg = yhjg;
    }

    public String getHang_resource_number() {
        return hang_resource_number;
    }

    public void setHang_resource_number(String hang_resource_number) {
        this.hang_resource_number = hang_resource_number;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Double getXscbzh() {
        return xscbzh;
    }

    public void setXscbzh(Double xscbzh) {
        this.xscbzh = xscbzh;
    }

    public Double getXslr() {
        return xslr;
    }

    public void setXslr(Double xslr) {
        this.xslr = xslr;
    }

    public Double getCkbhse() {
        return ckbhse;
    }

    public void setCkbhse(Double ckbhse) {
        this.ckbhse = ckbhse;
    }

    public Kh getKh() {
        return kh;
    }

    public void setKh(Kh kh) {
        this.kh = kh;
    }

    public Gg getJtwz() {
        return jtwz;
    }

    public void setJtwz(Gg jtwz) {
        this.jtwz = jtwz;
    }

    public String getCk() {
        return ck;
    }

    public void setCk(String ck) {
        this.ck = ck;
    }

    public Sjzdz getJzfs() {
        return jzfs;
    }

    public void setJzfs(Sjzdz jzfs) {
        this.jzfs = jzfs;
    }

    public Integer getJs() {
        return js;
    }

    public void setJs(Integer js) {
        this.js = js;
    }

    public Double getXscb() {
        return xscb;
    }

    public void setXscb(Double xscb) {
        this.xscb = xscb;
    }

    public Double getSbsl() {
        return sbsl;
    }

    public void setSbsl(Double sbsl) {
        this.sbsl = sbsl;
    }

    public Integer getCk_js() {
        return ck_js;
    }

    public void setCk_js(Integer ck_js) {
        this.ck_js = ck_js;
    }

    public Double getCk_sbsl() {
        return ck_sbsl;
    }

    public void setCk_sbsl(Double ck_sbsl) {
        this.ck_sbsl = ck_sbsl;
    }

    public Double getHsj() {
        return hsj;
    }

    public void setHsj(Double hsj) {
        this.hsj = hsj;
    }

    public Double getBhsj() {
        return bhsj;
    }

    public void setBhsj(Double bhsj) {
        this.bhsj = bhsj;
    }

    public Double getKcbj() {
        return kcbj;
    }

    public void setKcbj(Double kcbj) {
        this.kcbj = kcbj;
    }

    public Double getJsbhse() {
        return jsbhse;
    }

    public void setJsbhse(Double jsbhse) {
        this.jsbhse = jsbhse;
    }

    public Double getJsse() {
        return jsse;
    }

    public void setJsse(Double jsse) {
        this.jsse = jsse;
    }

    public Double getCbdj() {
        return cbdj;
    }

    public void setCbdj(Double cbdj) {
        this.cbdj = cbdj;
    }

    public Double getCbje() {
        return cbje;
    }

    public void setCbje(Double cbje) {
        this.cbje = cbje;
    }

    public String getBz() {
        return bz;
    }

    public void setBz(String bz) {
        this.bz = bz;
    }

    public Xsd getXsd() {
        return xsd;
    }

    public void setXsd(Xsd xsd) {
        this.xsd = xsd;
    }

    public Jsd getXsjsd() {
        return xsjsd;
    }

    public void setXsjsd(Jsd xsjsd) {
        this.xsjsd = xsjsd;
    }

    public Boolean getYjs() {
        return yjs;
    }

    public void setYjs(Boolean yjs) {
        this.yjs = yjs;
    }

    public Long getMxh() {
        return mxh;
    }

    public void setMxh(Long mxh) {
        this.mxh = mxh;
    }

    public String getJsfs() {
        return jsfs;
    }

    public void setJsfs(String jsfs) {
        this.jsfs = jsfs;
    }

    public Double getSe() {
        return se;
    }

    public void setSe(Double se) {
        this.se = se;
    }

    public List<Jfmx> getJfmxList() {
        return jfmxList;
    }

    public void setJfmxList(List<Jfmx> jfmxList) {
        this.jfmxList = jfmxList;
    }

    public Double getGhje() {
        return ghje;
    }

    public void setGhje(Double ghje) {
        this.ghje = ghje;
    }
}
